using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class Admin_UnitPriceAdd : System.Web.UI.Page
{
    #region Variable
    protected long Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (long)o;
            return long.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        if (Request.QueryString["id"] != null)
        {
            this.Id = long.Parse(Request.QueryString["id"].ToString());
        }
        LoadData();
        LoadCurent();

    }

    #region LoadCurent
    private void LoadCurent()
    {
        HtmlGenericControl ulProduct = (HtmlGenericControl)Master.FindControl("ulProduct");
        ulProduct.Attributes.Add("class", "current");
        HtmlControl divSelectSubPro = (HtmlControl)Master.FindControl("divSelectSubPro");
        divSelectSubPro.Attributes.Add("class", "select_sub show");
        HtmlGenericControl liCatPro = (HtmlGenericControl)Master.FindControl("liCatPro");
        liCatPro.Attributes.Add("class", "sub_show");

    }
    #endregion
    #region LoadData
    private void LoadData()
    {
        //ADESSA.Entities.ProductCat _ProductCat = new ADESSA.Entities.ProductCat();
        ADESSA.Entities.UnitPrice _UnitPrice = new ADESSA.Entities.UnitPrice();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            //_ProductCat = ProductCatService.GetProductCat(this.Id);
            _UnitPrice = UnitPriceService.GetUnitPrice(this.Id);
            if (_UnitPrice != null)
            {
                //txtName.Value = _ProductCat.Name;
                //txtOrder.Value = _ProductCat.SortOrder.ToString();
                //txtDes.Value = _ProductCat.Description;
                txtTitle.Value = _UnitPrice.Title;
                txtOrder.Value = _UnitPrice.Order.ToString();
                txtDes.Value = _UnitPrice.Summary;
            }
        }
    }
    #endregion
    #region VoidSave and Reset
    protected void btnsave_Click(object sender, EventArgs e)
    {
        //ADESSA.Entities.ProductCat _ProductCat = new ADESSA.Entities.ProductCat();
        ADESSA.Entities.UnitPrice _UnitPrice = new ADESSA.Entities.UnitPrice();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            _UnitPrice = UnitPriceService.GetUnitPrice(this.Id);
            //_ProductCat = ProductCatService.GetProductCat(this.Id);
        }
        //_ProductCat.Name = txtName.Value.Trim();
        //_ProductCat.SortOrder = Utility.ParseToBigint(txtOrder.Value.Trim());
        //_ProductCat.Description = txtDes.Value.Trim();
        //_ProductCat.Parrentid = 0;
        //_ProductCat.CatLevel = 0;
        _UnitPrice.Title = txtTitle.Value.Trim();
        _UnitPrice.Order = Utility.ParseToBigint(txtOrder.Value.Trim());
        _UnitPrice.Summary = txtDes.Value.Trim();
        _UnitPrice.Enable = true;
        if (this.Id != long.MinValue && this.Id != 0)
        {
            //ProductCatService.UpdateProductCat(_ProductCat);
            UnitPriceService.UpdateUnitPrice(_UnitPrice);
            Response.Redirect("UnitPriceList.aspx");
        }
        else
        {
            //_ProductCat.Enable = true;
            //ProductCatService.CreateProductCat(_ProductCat);
            _UnitPrice.Enable = true;
            UnitPriceService.CreateUnitPrice(_UnitPrice);
            Response.Redirect("UnitPriceList.aspx");
        }
    }
    protected void btnexit_Click(object sender, EventArgs e)
    {
        Response.Redirect("UnitPriceList.aspx");
    }
    #endregion
}
